<%@ page language="java" isELIgnored="false" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<jsp:directive.include file="/WEB-INF/sitemesh-decorators/include.jsp"/>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<fmt:setBundle basename="bundles.thesis-resources"/>
<div id="mainBody">
<script type="text/javascript">
    var infoList_s;
  	var num_of_arts;
  	var ipp;

  	function handlePaginationClick(new_page_index, pagination_container) {
  	    var pc = $(pagination_container);
  	    pc.children('div.infoList').remove();
  	 	pc.append('<br/><br/>')
   	 	var paginationClone = $("#Pagination > *").clone(true);
        $("#Pagination2").empty();
        paginationClone.appendTo("#Pagination2"); 
  	    for(var i=new_page_index*ipp; i < (new_page_index+1)*ipp ;i++) {
  	        if (i < num_of_arts) {
  	                pc.append(infoList_s[i]);
  	        }
  	    }

  	    return false;
  	}

  	$(document).ready(function() {
  		infoList_s = $('div.infoList').remove();
  	    num_of_arts = infoList_s.length;
  	    ipp = 5;

  	    // First Parameter: number of items
  	    // Second Parameter: options object
  	    $("#Pagination").pagination(num_of_arts, {
  	        items_per_page:ipp, 
  	        callback:handlePaginationClick
  	    });
  	}); 
  	

	</script> 
    <!-- InstanceBeginEditable name="main" -->
  	<div class="title">Thesis</div>
    	<form id="searchForm" action="search.html" method="post">
        <div id="search">
            <div id="searchBox">
                <textarea id="searchTerm" name="searchTerm" rows="1">${searchTerm}</textarea><button type="submit" id="goButton">GO</button>
          	</div>
      		<div id="searchOptions">
                <div>
                    <input class="advSearch thesis" type="checkbox" name="thesis" value="yes" checked /> Theses
                    <input class="advSearch facResearch" type="checkbox" name="research" value="yes" /> Faculty Research
                </div>
          	</div>
        </div>
        </form>
  
  	
  		<security:authorize ifNotGranted="ROLE_ADMIN" >
  		    <div id="Pagination"> </div>
		    <!-- <div id="Paginationcontent"> </div> -->
		    <div id="Pagination2"> </div>
    	<%-- <div class="cats">
        	<div><a href="index.html">Category</a></div>
            <div><a href="index.html">Category</a></div>
            <div><a href="index.html">Category</a></div>
            <div><a href="index.html">Category</a></div>
            <div><a href="index.html">Category</a></div>
            <div><a href="index.html">Category</a></div>
            <div><a href="index.html">Category</a></div>
            <div><a href="index.html">Category</a></div>
        </div>
        --%>
    	<div>
    		
    		<c:forEach var="thesis" items="${thesiss}">
            <div class="infoList">
                <div class="link"><a href="${pageContext.request.contextPath}/selectThesis.html?thesisIdKey=${thesis.thesisId }">${thesis.title}</a></div>
                <div class="abs"><p>${thesis.abstract_ }</p></div>
                <div class="props">
                    <div><a title="Student" href="searchThesisByStudentId.html?id=${thesis.student.studentId }">${thesis.student.firstName } ${thesis.student.lastName }</a></div>
                    <div>
                    
                    <c:forEach items="${thesis.categories }" var="category" varStatus="rowCounter">
                    	<a title="Thesis category" href="searchThesisByCategoryId.html?id=${category.categoryId }">${category.categoryDescription }</a>
                    	<c:if test="${!rowCounter.last}">,</c:if>
                    </c:forEach>
                    </div>
                    <c:forEach items="${thesis.thesiscommittees}" var="thesiscommittee">
                    <div>
                    <a title="Thesis Chair" href="searchThesisByChair.html?id=${thesiscommittee.facultyByChair.facultyId}">
                   		 ${thesiscommittee.facultyByChair.firstName}&nbsp;${thesiscommittee.facultyByChair.lastName}</a></div>
                    </c:forEach>
                </div>
            </div>
            </c:forEach>
            
        </div>


        </security:authorize>
        <security:authorize ifAllGranted="ROLE_ADMIN">
        <div id="table">
	        <div class="header">
	        	<div>&nbsp;</div>
	            <div>Title</div>
	            <div>Description</div>
	            <div>Student</div>
	            <div>Start Date</div>
	        </div>
	      
	        <c:forEach items="${thesiss}" var="thesis">
	        
	        <div class="row">
	        	<div>
	        		<a title="<fmt:message key="navigation.view" />" href="${pageContext.request.contextPath}/selectThesis?thesisIdKey=${thesis.thesisId}&"><img src="includes/images/icons/view.gif" /></a>
						<a title="<fmt:message key="navigation.edit" />" href="${pageContext.request.contextPath}/editThesis?thesisIdKey=${thesis.thesisId}&"><img src="includes/images/icons/edit.gif" /></a>
						<a title="<fmt:message key="navigation.delete" />" href="${pageContext.request.contextPath}/confirmDeleteThesis?thesisIdKey=${thesis.thesisId}&"><img src="includes/images/icons/delete.gif" /></a>
	        	</div>
	            <div>${thesis.title }</div>
	            <div>${thesis.abstract_ }</div>
	            <div>${thesis.student.lastName }, ${thesis.student.firstName }</div>
	            <div>${thesis.startDate.time }</div> 
	        </div>
	        
	        </c:forEach>
	        
        </div>
        </security:authorize>
	
  </div>